class Solution {
public:
    int jump(int A[], int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        vector<int> dp(n);
        dp[0] = 0;
        int end = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = end + 1; j < n && j <= i + A[i]; ++j) {
                dp[j] = dp[i] + 1;
            }
            end = max(end, i + A[i]);
        }
        return dp[n - 1];
    }
};
